package com.ruoyi.kaifa.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.kaifa.domain.ASort;
import com.ruoyi.kaifa.domain.vo.AUserVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.kaifa.domain.AQuest;
import com.ruoyi.kaifa.service.IAQuestService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 任务Controller
 *
 * @author ruoyi
 * @date 2024-10-01
 */
@RestController

@RequestMapping("/kaifa/quest")
public class AQuestController extends BaseController
{
    @Autowired
    private IAQuestService aQuestService;

    /**
     * 查询任务列表
     */
//    @PreAuthorize("@ss.hasPermi('kaifa:quest:list')")
    @GetMapping("/list")
    @RequestMapping("/list")
    public Object list(AQuest aQuest)
    {
        startPage();
        List<ASort> sortList = aQuestService.selectASortList();
        List<AQuest> list = aQuestService.selectAQuestList(aQuest);
        List<AUserVo> userList = aQuestService.selectAUserVoList();
        Map<String, Object> map = new HashMap<>();
        map.put("sortList", sortList);
        map.put("list", getDataTable(list));
        map.put("userList", userList);
        return map;
    }

    /**
     * 导出任务列表
     */
    @PreAuthorize("@ss.hasPermi('kaifa:quest:export')")
    @Log(title = "任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AQuest aQuest)
    {
        List<AQuest> list = aQuestService.selectAQuestList(aQuest);
        ExcelUtil<AQuest> util = new ExcelUtil<AQuest>(AQuest.class);
        util.exportExcel(response, list, "任务数据");
    }

    /**
     * 获取任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('kaifa:quest:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(aQuestService.selectAQuestById(id));
    }

    /**
     * 新增任务
     */
    @PreAuthorize("@ss.hasPermi('kaifa:quest:add')")
    @Log(title = "任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AQuest aQuest)
    {
        return toAjax(aQuestService.insertAQuest(aQuest));
    }

    /**
     * 修改任务
     */
    @PreAuthorize("@ss.hasPermi('kaifa:quest:edit')")
    @Log(title = "任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AQuest aQuest)
    {
        return toAjax(aQuestService.updateAQuest(aQuest));
    }

    /**
     * 删除任务
     */
    @PreAuthorize("@ss.hasPermi('kaifa:quest:remove')")
    @Log(title = "任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(aQuestService.deleteAQuestByIds(ids));
    }
}
